from fastapi import Request
from config.env import RedisInitKeyConfig
from core.dao.car_track_dao import *
from core.entity.vo.car_track_vo import *
from core.entity.vo.common import CrudResponse
from utils.common_util import export_list2excel


class CarTrackService:
    """
    参数配置管理模块服务层
    """

    @classmethod
    def get_car_track_by_id(cls, result_db: Session, id: int):
        """
        获取参数配置列表信息service
        :param result_db: orm对象
        :param query_object: 查询参数对象
        :return: 参数配置列表信息对象
        """
        car_track = CarTrackDao.get_car_track_by_id(result_db, id)

        return car_track

    @classmethod
    def get_car_track_by_car_id(cls, result_db: Session, carId: str):
        """
        获取参数配置列表信息service
        :param result_db: orm对象
        :param query_object: 查询参数对象
        :return: 参数配置列表信息对象
        """
        car_track_list = CarTrackDao.get_car_track_by_car_id(result_db, carId)

        return car_track_list

    @classmethod
    async def add_car_track_services(cls, request: Request, result_db: Session, carTrack: CarTrackModel):
        """
        新增参数配置信息service
        :param request: Request对象
        :param result_db: orm对象
        :param page_object: 新增参数配置对象
        :return: 新增参数配置校验结果
        """
        try:
            CarTrackDao.add_car_track_dao(result_db,carTrack)
            result_db.commit()
            result = dict(is_success=True, message='新增成功')
        except Exception as e:
            result_db.rollback()
            result = dict(is_success=False, message=str(e))
        return CrudResponse(**result)

    @classmethod
    async def edit_config_services(cls, request: Request, result_db: Session, carTrack: CarTrackModel):
        """
        编辑参数配置信息service
        :param request: Request对象
        :param result_db: orm对象
        :param page_object: 编辑参数配置对象
        :return: 编辑参数配置校验结果
        """
        try:
            CarTrackDao.edit_car_track_dao(result_db, carTrack)
            result_db.commit()
            result = dict(is_success=True, message='修改成功')
        except Exception as e:
            result_db.rollback()
            result = dict(is_success=False, message=str(e))
        return CrudResponse(**result)

